/* 
 * Copyright (C) 2012 Martin Řehánek <Martin.Rehanek at mzk.cz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

goog.provide('kramerius.audio.ui.PlaylistShowHideButton');

goog.require('kramerius.audio.ui.Button');

/** @const */ 
var PLAYLIST_ON = 'btnPlaylistOn';
/** @const */ 
var PLAYLIST_OFF = 'btnPlaylistOff';

/** @const */ 
var SHOW_AND_HIDE_PLAYLIST_BUTTON_STATE_PLAYLIST_ON = 'PLAYLIST_ON';
/** @const */ 
var SHOW_AND_HIDE_PLAYLIST_BUTTON_STATE_PLAYLIST_OFF = 'PLAYLIST_OFF';

/**
 * @constructor 
 * @param {Element} container Element containing this button.
 * @param {kramerius.audio.Controller} controller Controller of the audio player.
 */
kramerius.audio.ui.PlaylistShowHideButton =  function(container, controller){
    kramerius.audio.ui.Button.call(this, container, controller);
    this.controller_.setPlaylistShowHideButton(this);
    /** @private */
    this.btnControl = this.initializeControl_();
    //TODO: defaultne ze startu zobrazit
    this.setStatePlaylistOn();
    //this.setStatePlaylistOff();
};
goog.inherits(kramerius.audio.ui.PlaylistShowHideButton, kramerius.audio.ui.Button);


/** @private */
kramerius.audio.ui.PlaylistShowHideButton.prototype.initializeControl_ = function(){
    var btnControl = new goog.ui.Control();
    btnControl.setDispatchTransitionEvents(goog.ui.Component.State.ACTION, true);
    var controller = this.controller_;
    var button = this;
    goog.events.listen(btnControl, goog.ui.Component.EventType.ACTION,
        function (e) {
            if (button.getState() == SHOW_AND_HIDE_PLAYLIST_BUTTON_STATE_PLAYLIST_OFF){
                    console.log("PlaylistShowHideButton: showing");
                    controller.showPlaylist();
            }else{
                    console.log("PlaylistShowHideButton: hiding");
                    controller.hidePlaylist();
            }
        });
    //kramerius.audio.debug_utils.appendDebugListeners(btnControl, "play button");
    btnControl.decorate(this.container_);
    return btnControl;
};

kramerius.audio.ui.PlaylistShowHideButton.prototype.getState = function(){
    return this.state_;
};


kramerius.audio.ui.PlaylistShowHideButton.prototype.setStatePlaylistOff = function(){
    this.state_ = SHOW_AND_HIDE_PLAYLIST_BUTTON_STATE_PLAYLIST_OFF;
    this.setContainerClass_(PLAYLIST_OFF);    
    //TODO: i18n tooltip
    new goog.ui.Tooltip(this.container_, "zobrazit seznam skladeb");
};


kramerius.audio.ui.PlaylistShowHideButton.prototype.setStatePlaylistOn = function(){
    this.state_ = SHOW_AND_HIDE_PLAYLIST_BUTTON_STATE_PLAYLIST_ON;
    this.setContainerClass_(PLAYLIST_ON);
    //TODO: i18n tooltip
    new goog.ui.Tooltip(this.container_, "skrýt seznam skladeb");
};


